<template>
  <div class="app-container">
    <!--使用v-loading在接口为请求到数据之前，显示加载中，直到请求到数据后消失。-->
    <el-table
      v-loading="listLoading"
      border
      fit
      highlight-current-row
      :data="tableData"
      border
      style="width: 100%"
    >
      <el-table-column
        v-for="(item,key) in titleData"
        :key="key"
        align="center"
        :prop="item"
        :label="item"
      />
    </el-table>
    <!--v-show 属性通过判断total是否大于0来决定是否显示-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { fetchList } from '@/api/testDemo'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

export default {
  name: 'ArticleList',
  components: { Pagination },
  data() {
    return {
      tableData: null,
      titleData: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.total = response.data.total
        this.tableData = response.data.tableData
        this.titleData = response.data.titleData
        console.log(this.tableData)
        console.log(this.titleData)
        this.listLoading = false
      })
    }
  }
}
</script>

<style scoped>
  .edit-input {
    padding-right: 100px;
  }

  .cancel-btn {
    position: absolute;
    right: 15px;
    top: 10px;
  }
</style>
